package com.wuyan.locationdog.ui.my


import androidx.activity.viewModels
import com.arcsoft.commonbase.base.BaseBindingActivity
import com.arcsoft.commonbase.bus.Bus
import com.arcsoft.commonbase.bus.bus_update_userinfo
import com.arcsoft.commonbase.ext.loadImageCircle
import com.blankj.utilcode.util.ActivityUtils
import com.wuyan.locationdog.databinding.MyInfoActivityBinding
import com.wuyan.locationdog.help.DeviceHelp
import com.wuyan.locationdog.viewmodel.MyViewModel

class MyInfoActivity : BaseBindingActivity<MyInfoActivityBinding>() {
    private val mViewModel: MyViewModel by viewModels()

    override fun initData() {
        setTitleText("",true)

        binding.apply {
            btnPhoto.setOnClickListener {
                ActivityUtils.startActivity(MyPhotoActivity::class.java)
            }
            btnNickName.setOnClickListener {
                ActivityUtils.startActivity(MyNickNameActivity::class.java)
            }
            btnPhone.setOnClickListener {
                ActivityUtils.startActivity(MyModifyPhoneActivity::class.java)
            }
            btnModifyPwd.setOnClickListener {
                DeviceHelp.isDeviceModifyPwd = false

                ActivityUtils.startActivity(MyModifyPwdActivity::class.java)
            }
        }

        mViewModel.getMyInfo(hashMapOf())

    }

    override fun observe() {
        super.observe()
        Bus.observe<String>(bus_update_userinfo, this) {
            mViewModel.getMyInfo(hashMapOf())
        }
//        mViewModel.anyBean.observe(this) {
//            mViewModel.getMyInfo(hashMapOf())
//        }

        mViewModel.myInfoBean.observe(this) {
            binding.apply {
                tvNickName.text = it.content.nickName
                userCode.text = it.content.userCode
                userPhone.text = it.content.userPhone

                ivHead.loadImageCircle(it.content.avatarDTO.fileUrl)
            }

        }
    }
}